import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
const $time 				= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms:[
			{ label: '统计时间',		names: ['start_at','end_at'], 	name:'jz-time',	type: 'date-range' },
			{ label: '岗位',			name: 'project_id',				type: 'select', loading:true },
			{ label: '项目',			name: 'kind_id',				type: 'select', loading:true },
		]
		
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['1-9-9']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			this.fetch()
		})
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 项目
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'labkindselect' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'Specimen/laboratoryListsCount')
	
	// 表单
	cols = [
		{ title: '岗位', 		dataIndex: 'project_name', 		width:150 },
		{ title: '项目名称', 	dataIndex: 'kind_name', 		width:150 },
		{ title: '数量', 		dataIndex: 'count', 			...$fn.table.num },
		{ title: '标准收费', 	dataIndex: 'price', 			...$fn.table.num },
		{ title: '实际收费', 	dataIndex: 'sprice', 			...$fn.table.num },
	]
	
	render(){
		return (
			<>
				<Page title='项目统计单'>
					{/* 搜索 */}
					{ SearchForm.call(this, { timeStr:'1-9-9' }) }
					{/* 表格 */}
					{ 
						Table.call(this)
					}
				</Page>
			</>
		)
	}
}

export default Index